function getLoginStatus() {
    var loggedIn = false;
    FB.getLoginStatus(function(response) {
                      if (response.status == 'connected') {
                      loggedIn = true;
                      } else {
                      loggedIn = false;
                      }
                      });
    return loggedIn;
}

var friendIDs = [];
var fdata;
function getFriendsList() {
    var friends;
    FB.api('/me/friends', { fields: 'id, name, picture' },  function(response) {
           if (response.error) {
           alert(JSON.stringify(response.error));
           } else {
           var data = document.getElementById('data');
           fdata=response.data;
           console.log("fdata: "+fdata);
           response.data.forEach(function(item) {
                                 var d = document.createElement('div');
                                 d.innerHTML = "<img src="+item.picture+"/>"+item.name;
                                 data.appendChild(d);
                                 });
           }
           friends = response.data;
           console.log(friends.length);
           for (var k = 0; k < friends.length && k < 200; k++) {
           var friend = friends[k];
           var index = 1;
           
           friendIDs[k] = friend.id;
           }
           console.log("friendId's: "+friendIDs);
           });
}

function logout() {
    FB.logout(function(response) {
              alert('logged out');
              });
}

function login() {
    FB.login(function(response) {
             if (response.authResponse) {
             console.log('Welcome!  Fetching your information.... ');
             } else {
             console.log('User cancelled login or did not fully authorize.');
             }
             });
}

function fbInit() {
    console.log('fbInit');
    FB.init({ appId: "470782169676577", nativeInterface: CDV.FB, useCachedDialogs: false });
}

